package com.ding.manager.util;

import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.util.Properties;

/**
 * <pre>
 * 对象功能:常量文件constant.properties解析帮助工具类
 * 开发人员:lixin
 * 创建时间:2018-01-15
 * </pre>
 */
@Component
public class ConstantMsgUtil {

	private static Properties pros = new Properties();

	public ConstantMsgUtil() {
		init();
	}

	private void init() {
		InputStream inStream = getClass().getClassLoader().getResourceAsStream("config/constantMsg.properties");
		try {
			if (inStream != null) {
				pros.load(inStream);
				inStream.close();
			} else {
				System.out.println("config/constantMsg.properties没有找到,无法启动项目,请重新配置!");
				System.exit(0);
//				throw new Exception("config/constantMsg.properties没有找到,请重新配置!");
			}
		} catch (Exception e) {
			System.exit(0);
			e.printStackTrace();
		} finally {
			if (inStream != null) {
				try {
					inStream.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static String getProperty(String key) {
		return pros.getProperty(key);
	}

	public static Properties getPros() {
		return pros;
	}

	public void update() {
		init();
	}

	/** 添加成功提示 **/
	public static String getInsertSuccMsg() {
		return getProperty("insertSuccMsg");
	}

	/** 添加失败提示 **/
	public static String getInsertFailMsg() {
		return getProperty("insertFailMsg");
	}

	/** 修改成功提示 **/
	public static String getUpdateSuccMsg() {
		return getProperty("updateSuccMsg");
	}

	/** 修改失败提示 **/
	public static String getUpdateFailMsg() {
		return getProperty("updateFailMsg");
	}

	/** 保存成功提示 **/
	public static String getSaveSuccMsg() {
		return getProperty("saveSuccMsg");
	}

	/** 保存失败提示 **/
	public static String getSaveFailMsg() {
		return getProperty("saveFailMsg");
	}

	/** 删除成功提示 **/
	public static String getDeleteSuccMsg() {
		return getProperty("deleteSuccMsg");
	}

	/** 删除失败提示 **/
	public static String getDeleteFailMsg() {
		return getProperty("deleteFailMsg");
	}

	/** 查询成功提示 **/
	public static String getQuerySuccMsg() {
		return getProperty("querySuccMsg");
	}

	/** 查询失败提示 **/
	public static String getQueryFailMsg() {
		return getProperty("queryFailMsg");
	}

	/** 操作成功状态:0 **/
	public static int getSuccStatus() {
		return Integer.valueOf(getProperty("succStatus"));
	}

	/** 操作成功提示 **/
	public static String getSuccMsg() {
		return getProperty("succMsg");
	}

	/** 操作失败状态:1 **/
	public static int getFailStatus() {
		return Integer.valueOf(getProperty("failStatus"));
	}

	/** 操作失败提示 **/
	public static String getFailMsg() {
		return getProperty("failMsg");
	}

	/** Session超时状态:2 **/
	public static int getSessionTimeOutStatus() {
		return Integer.valueOf(getProperty("sessionTimeOutStatus"));
	}

	/** Session超时提示 **/
	public static String getSessionTimeOutMsg() {
		return getProperty("sessionTimeOutMsg");
	}

	/** 网络异常状态:3 **/
	public static int getInternetStopStatus() {
		return Integer.valueOf(getProperty("internetStopStatus"));
	}

	/** 网络异常提示 **/
	public static String getInternetStopMsg() {
		return getProperty("internetStopMsg");
	}

	/** 相同帐号登录状态:4 **/
	public static int getAccountControlStatus() {
		return Integer.valueOf(getProperty("accountControlStatus"));
	}

	/** 相同帐号登录提示 **/
	public static String getAccountControlMsg() {
		return getProperty("accountControlMsg");
	}

}
